'use strict';

const Controller = require('egg').Controller;
const { getCookieValue } = require('../public/processCookies');
/**
* @controller SnListController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class SnListController extends Controller {
  async list() {
    /**
        * @summary snlist
        * @description snlist
        * @router get /snlist
        * @request query integer limit
        * @request query integer page
        * @request query string search
       */
    const params = this.ctx.query;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.snList.list(params);
    this.ctx.body = {
      msg: '',
      status: 200,
      data: result.rows,
      count: result.count,
    };
  }
  async create() {
    /**
        * @summary sncreate
        * @description sncreate
        * @router post /sncreate
        * @request body sncreate value 传入参数
        */
    const params = this.ctx.request.body;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    await this.ctx.service.snList.create(params);
    this.ctx.body = {
      msg: 'create successful',
    };
  }
  async delete() {
    /**
        * @summary sndelete
        * @description sndelete
        * @router get /sndelete
        * @request query String id
        */
    const params = this.ctx.query;
    await this.ctx.service.snList.delete(params);
    this.ctx.body = {
      msg: 'delete successful',
    };
  }
  async snverify() {
    /**
        * @summary snverify
        * @description snverify
        * @router get /snverify
        * @request query string SN
        */
    const params = this.ctx.query;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.snList.snverify(params);
    this.ctx.body = {
      msg: result.msg,
      data: result.flag,
    };
  }
  async tr069List() {
    /**
        * @summary tr069SNList
        * @description tr069SNList
        * @router get /tr069snlist
        * @request query integer limit
        * @request query integer page
        * @request query string search
        * @request query string group
        * @request query string order
        * @request query string sort
       */
    const params = this.ctx.query;
    const { id: tid } = getCookieValue(this.ctx.cookies, 'token', 'tenant');
    params.tid = tid;
    const result = await this.ctx.service.snList.tr069List(params);
    this.ctx.body = {
      msg: '',
      status: 200,
      data: result.rows,
      count: result.count,
    };
  }
}

module.exports = SnListController;
